#pragma once

#include <atomic>
#include <memory>
#include "base_noncopyable.h"
#include "common_media_define.h"
#include "media_frame.h"
#include "base_callback_list.h"

namespace El {
namespace Media {

class StreamSourceManager {
    DISALLOW_COPY_AND_MOVE(StreamSourceManager);
    StreamSourceManager(int32_t ch, int32_t type);
    ~StreamSourceManager();

public:
    using Proc = std::function<void(const MediaFramePtr &)>;

    static StreamSourceManager &GetInstance(int32_t ch, int32_t type);

    int32_t Start(const Proc &proc);

    void Stop(int32_t handle);

private:
    void OnStream(MediaFramePtr &media);

private:
    int32_t ch_{0};
    int32_t type_{0};
    std::atomic<bool> start_{false};
    std::mutex mutex_;

    Base::CallbackList<void, const MediaFramePtr &> callbackManager_;

    int32_t halHandle_{0};
    int32_t halAudioHandle_{0};
};

} // namespace Media
} // namespace El